//
//  ParadiscViewController.m
//  Education
//
//  Created by 流风幻雾 on 15/7/14.
//  Copyright (c) 2015年 HUA. All rights reserved.
//
#define KurlOfChildrenSong @"http://app.9nali.com/759/albums/222223?page_id=1&isAsc=true&device=iPhone&version=2.3.1"
#define KurlOfChirdrenStory @"http://app.9nali.com/759/albums/299581?page_id=1&isAsc=true&device=iPhone&version=2.3.1"
#define KurlOfBedStory @"http://app.9nali.com/759/albums/202812?page_id=1&isAsc=true&device=iPhone&version=2.3.1"
#define KurlOfThousandStory @"http://app.9nali.com/759/albums/257813?page_id=1&isAsc=true&device=iPhone&version=2.3.1"
#define KurlOfChildrenEnglish @"http://app.9nali.com/759/albums/302340?page_id=1&isAsc=true&device=iPhone&version=2.3.1"
#define KurlOfEnglishSong @"http://app.9nali.com/759/albums/302?page_id=2&isAsc=true&device=iPhone&version=2.3.1"

#import "ParadiscViewController.h"
#import "ParadiscViewModel.h"
#import "LORequestManger.h"
#import "CollectionViewCell.h"
#import "SongListTableViewController.h"
#import "BackImageView.h"
@interface ParadiscViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(strong,nonatomic)UICollectionView *collectionView;
@property(strong,nonatomic)UICollectionViewFlowLayout *flowLayout;
@property(strong,nonatomic)NSMutableArray *modelArray;
@property(strong,nonatomic)NSArray *urlArray;

@end

@implementation ParadiscViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) collectionViewLayout:_flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    BackImageView *backImage = [[BackImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.collectionView.backgroundView = backImage;
    [self.view addSubview:self.collectionView];
    self.urlArray = @[KurlOfChildrenSong,KurlOfChirdrenStory,KurlOfBedStory,KurlOfThousandStory,KurlOfChildrenEnglish,KurlOfEnglishSong];
    [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.modelArray = [NSMutableArray array];
    for (int i = 0; i < 6; i ++)
    {

        ParadiscViewModel *model = [[ParadiscViewModel alloc]init];
        [self.modelArray addObject:model];
        [LORequestManger GET:_urlArray[i] success:^(id response) {
                NSDictionary *dic = (NSDictionary *)response;
                NSDictionary *albumDic = dic[@"album"];
                [model setValueWithDictionary:albumDic];
                NSDictionary *tracksDic = dic[@"tracks"];
                [model setValueWithDictionary:tracksDic];
                [self.collectionView reloadData];
        } failure:nil];
    }
}




//返回item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

//返回分区个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//返回cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell setValueWithModel:self.modelArray[indexPath.item] indexpath:indexPath];
    return cell;
}

//返回每个item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kScreenHeight * 0.22,kScreenWidth * 0.49);
}


//返回间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(kScreenWidth * 0.02, kScreenWidth * 0.08, 0, kScreenWidth * 0.08);
}


//添加点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

        SongListTableViewController *songListVc = [[SongListTableViewController alloc]init];
        [self setSongListVcValueWith:songListVc indexpath:indexPath];
        [self.navigationController pushViewController:songListVc animated:YES];

}



//属性传值的封装
- (void)setSongListVcValueWith:(SongListTableViewController *)songListVc indexpath:(NSIndexPath *)indexPath
{
    songListVc.listArray = [self.modelArray[indexPath.item] list];
    songListVc.totalCount = [self.modelArray[indexPath.item] totalCount];
    songListVc.titleName = [self.modelArray[indexPath.item] title];
    songListVc.smallLogo = [self.modelArray[indexPath.item] smallLogo];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}



@end
